-
Notifications
You must be signed in to change notification settings - Fork 72
custom client option #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
custom client option #89
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a CustomClient field to the PushOptions struct to enable users to specify a custom HTTP client for metric pushing. This addresses the need for mutual TLS authentication with client certificates when pushing metrics to VictoriaMetrics instances without modifying the global HTTP DefaultTransport.
- Added
CustomClient *http.Clientfield toPushOptionsstruct for custom HTTP client configuration - Modified the client creation logic in
newPushContextto use the provided custom client or fall back to default - Added comprehensive test coverage to verify custom client functionality with TLS configurations
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| push.go | Adds CustomClient field to PushOptions and modifies newPushContext to use custom or default client |
| push_test.go | Adds test coverage for custom client functionality with TLS configuration scenarios |
Comments suppressed due to low confidence (1)
push_test.go:290
- The test relies on string matching to verify TLS-related errors, which is brittle. Consider using error type assertions or wrapping errors to make the test more robust and specific.
// Verify the error is TLS-related
| } | ||
|
|
||
| func TestCustomClientWithTLSConfig(t *testing.T) { | ||
| // Create a TLS configuration that accepts self-signed cert |
Copilot
AI
Jul 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The comment should use 'certificates' instead of 'cert' for proper grammar.
| // Create a TLS configuration that accepts self-signed cert | |
| // Create a TLS configuration that accepts self-signed certificate |
| // CustomClient allows specifying a custom HTTP client for making the push requests. | ||
| // | ||
| // If nil, the default http.Client will be created. | ||
| CustomClient *http.Client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, it's more clear to name it just as Client and add a comment, that it's optional http client for making push requests.
Add CustomClient option to PushOptions
Problem
When pushing metrics to a VictoriaMetrics Instance that requires mutual TLS authentication with client certificates, the current implementation doesn't allow customizing the HTTP client used for requests. This creates a dilemma:
Solution
Add a
CustomClientfield to thePushOptionsstruct that allows specifying a custom HTTP client. This enables users to configure TLS settings specifically for metrics pushing without affecting other parts of the application.Why Not Use vmauth or Traefik?
While vmauth and Traefik are excellent solutions for many scenarios, there are specific use cases where a custom client approach provides significant advantages:
Cross-cloud deployments: When the metrics client is in one cloud provider and the VictoriaMetrics server is in another, setting up an additional proxy layer introduces unnecessary complexity and potential points of failure.
Network complexity: Cross-cloud communications typically traverse public internet, making embedded TLS configuration simpler and more secure than exposing and securing additional proxy services.
Operational simplicity: For many users, configuring the client directly eliminates the need to deploy, manage, and secure additional infrastructure components.
This implementation provides flexibility for users to choose the approach that best fits their specific infrastructure and security requirements.
Use Case
This is particularly useful in multi-cloud environments where metrics need to be pushed between services in different clouds requiring mutual TLS authentication. For example:
Changes
CustomClient *http.Clientfield toPushOptionsstructnewPushContextto use the provided client or create a default oneThe implementation maintains backward compatibility with all existing code.
Fixes #88